package org.bronycorps.mlptss.screen;

import org.bronycorps.mlptss.MlpTss;
import org.bronycorps.mlptss.manager.ScreenLoader;
import org.bronycorps.mlptss.utils.MenuInputListener;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;

public class MenuScreen extends AbstractMenuScreen {

	public MenuScreen() {
		super();
	}

	protected void addBackground() {
		// put background image
		Texture backgroundTexture = this.manager.get(
				this.config.convertPath(this.menuConfig.getBackground()),
				Texture.class);
		backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
		Image bgImage = new Image(backgroundTexture);
		this.stage.addActor(bgImage);
	}

	@Override
	public void show() {
		Gdx.input.setInputProcessor(this.stage);

		addBackground();

		// retrieve the default table actor
		getTable();

		Skin skin = getSkin();
		this.table.padTop(300);

		// register the button "start game"
		TextButton startGameButton = new TextButton("Start game", skin);
		startGameButton.addListener(new MenuInputListener() {

			@Override
			public void touchUp(InputEvent event, float x, float y,
					int pointer, int button) {
				Gdx.app.log(MlpTss.LOG, "opening start game");
				super.touchUp(event, x, y, pointer, button);
				ScreenLoader.getInstance().loadScreen(
						new CharacterSelectionScreen());
			}
		});
		this.table.add(startGameButton).size(200, 40).uniform().spaceBottom(10);
		this.table.row();

		// register the button "options"
		TextButton optionsButton = new TextButton("Options", skin);
		optionsButton.addListener(new InputListener() {

			@Override
			public void touchUp(InputEvent event, float x, float y,
					int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				// MenuScreen.this.game.setScreen(new OptionsScreen(
				// MenuScreen.this.game));
			}

		});
		this.table.add(optionsButton).uniform().fill().spaceBottom(10);
		this.table.row();

		// register the button "high scores"
		TextButton highScoresButton = new TextButton("High Scores", skin);
		highScoresButton.addListener(new InputListener() {
			@Override
			public void touchUp(InputEvent event, float x, float y,
					int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				// MenuScreen.this.game.setScreen(new HighScoresScreen(
				// MenuScreen.this.game));
			}
		});
		this.table.add(highScoresButton).uniform().fill().spaceBottom(10);
		this.table.row();

		// register the button "high scores"
		TextButton creditsButton = new TextButton("Credits", skin);
		creditsButton.addListener(new InputListener() {
			@Override
			public void touchUp(InputEvent event, float x, float y,
					int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				// MenuScreen.this.game.setScreen(new HighScoresScreen(
				// MenuScreen.this.game));
			}
		});
		this.table.add(creditsButton).uniform().fill();

	}
}
